<?php

class MemberForm extends BaseForm {
  const FORM_NAME                 = 'frm';

  const FIELD_MERCHANT_ID         = 'merchant_id';
  const FIELD_STATUS              = 'status';

  const SORT_FIRST_NAME           = 'FIRST_NAME';
  const SORT_LAST_NAME            = 'LAST_NAME';
  const SORT_CREATED_AT           = 'CREATED_AT desc';

  public function configure() {
    $arrStatusList = StringUtil::getStatusArray();

    $widget = array(
            self::FIELD_STATUS       => new sfWidgetFormSelect(array('choices' => $arrStatusList), array('multiple' => false, 'expand' => true))
    );

    $labels = array(
            self::FIELD_MERCHANT_ID  => 'Merchant Id',
            self::FIELD_STATUS       => 'status'
    );

    $this->setWidgets($widget);
    $this->widgetSchema->setLabels($labels);

    $validators = array(
            self::FIELD_STATUS       => new sfValidatorString(array('trim' => true), array('required' => LangUtil::getText('error_required', array($labels[self::FIELD_STATUS]))))
    );

    $this->setValidators($validators);
    $this->validatorSchema->setPostValidator(new sfValidatorCallback(array('callback' => array($this, 'postValidator'))));

    $this->widgetSchema->setNameFormat(self::FORM_NAME . '[%s]');

    $this->validatorSchema->setOption('allow_extra_fields', true);
    $this->validatorSchema->setOption('filter_extra_fields', false);
  }

  public function postValidator($validator, $values) {
    return $values;
  }

  public function populateData(USER $user) {
    $this->setDefault(self::FIELD_MERCHANT_ID, $user->getMerchantId());
    $this->setDefault(self::FIELD_STATUS, $user->getStatus());
  }
}
?>